const mongoose = require("mongoose");
const { errorsModel } = require("../models/errorsModel");
//获取所有错题
async function getErrors(req,res){
    let data = await mongoose.model(errorsModel).find(req.body).populate({
        path:"exerciseId",
        populate:{
            path:"pointId"
        }
    }).populate("studentId");
    res.send({
        message:"响应成功",
        code:200,
        data
    })
}
//删除错题
async function deleteErrors(req,res){
    await mongoose.model(errorsModel).deleteOne(req.body);
    let data = await mongoose.model(errorsModel).find().populate({
        path:"exerciseId",
        populate:{
            path:"pointId"
        }
    }).populate("studentId");
    res.send({
        message:"删除成功",
        code:200,
        data
    })
}
//添加错题
async function createErrors(req,res){
    await mongoose.model(errorsModel).create(req.body);
    let data = await mongoose.model(errorsModel).find().populate({
        path:"exerciseId",
        populate:{
            path:"pointId"
        }
    }).populate("studentId");
    res.send({
        message:"添加成功",
        code:200,
        data
    })
}
//
module.exports = {
    getErrors,
    deleteErrors,
    createErrors
}